
import {Http, Headers, RequestOptionsArgs} from "@angular/http";
import { Observable } from 'rxjs/Rx';
import {Injectable} from "@angular/core";
import {APP_CODE} from '../../app/common/app.config'

@Injectable()
export class MobileHttp{

  /** 阿里云数据申请的Key*/
  // private APP_CODE = '9a909bdd0ce843f7ab5a22b52274e99a';
  private headers = new Headers({'Authorization': 'APPCODE '+ APP_CODE});//APPCODE之后跟随空格
  private requestOptionsArgs :RequestOptionsArgs = {headers: this.headers};
  private shoujiUrl = `http://jshmgsdmfb.market.alicloudapi.com/shouji/query?shouji=`;
  // let url = `https://tcc.taobao.com/cc/json/mobile_tel_segment.htm?tel=${mobileNum}`;

  constructor(private http: Http){

  }
  searchAttribution(mobileNum:string){

    let url = this.shoujiUrl+mobileNum;
    return this.http.get(url,this.requestOptionsArgs)
      .map((response)=> response.json()) // 加map请求好慢好慢好慢。？？？？
      .catch((e)=>{
        return Observable.throw(
          new Error(`${ e.status } ${ e.statusText }`)
        );
      });
  }
}
